from rest_framework import serializers

from tweets.models import Tweet, Comment


class TweetListSerializer(serializers.ModelSerializer):
    """吐槽首页序列化器"""
    class Meta:
        model = Tweet
        fields = ['id', 'create_time', 'content', 'user_id']


class CommentSerializer(serializers.ModelSerializer):
    """吐槽详情序列化器"""

    class Meta:
        model = Comment
        fields = '__all__'
        depth = 2


class TweetDetailSerializer(serializers.ModelSerializer):
    """吐槽详情序列化器"""
    tweets_comment = CommentSerializer(many=True, read_only=True)

    class Meta:
        model = Tweet
        fields = '__all__'
        depth = 2

        # 利用AreaSerializer将ｓｕｂｓ里面的值以需要的ｉｄ和ｎａｍｅ形式传递出来
        # ｍａｎｙ默认多个，ｒｅａｄ＿ｏｎｌｙ返回时使用


class CreateTweetSerializer(serializers.ModelSerializer):
    """发表吐槽序列化器"""
    class Meta:
        model = Comment
        fields = ('count')